package 华为OD机试真题2023.基础题;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

public class HJ22_投篮大赛 {
    public static void main(String[] args) throws FileNotFoundException {
        Scanner in = new Scanner(new File("src/main/java/华为OD机试真题2023/基础题/input/22.txt"));
        String[] sArray = in.nextLine().split(" ");
        LinkedList<Integer> scoreList = new LinkedList<>();
        for (String s : sArray) {
            if ("C".equals(s)) {
                if (scoreList.size() < 1) {
                    System.out.println(-1);
                    return;
                }
                scoreList.removeLast();
            } else if ("D".equals(s)) {
                if (scoreList.size() < 1) {
                    System.out.println(-1);
                    return;
                }
                int score = 2 * scoreList.getLast();
                scoreList.addLast(score);
            } else if ("+".equals(s)) {
                if (scoreList.size() < 2) {
                    System.out.println(-1);
                    return;
                }
                int score = scoreList.getLast() + scoreList.get(scoreList.size() - 2);
                scoreList.addLast(score);
            } else {
                int score = Integer.parseInt(s);
                scoreList.addLast(score);
            }
        }
        int total = 0;
        for (int score : scoreList) {
            total += score;
        }
        System.out.println(total);
    }
}
